package com.cheyun.netsalev3.viewmodel

import android.content.Intent
import android.view.View
import androidx.lifecycle.Transformations
import com.cheyun.netsalev3.bean.OutlistParam
import com.cheyun.netsalev3.repository.BasePageRepository
import com.cheyun.netsalev3.view.defeatdetails.DefeatDetailsActivity

/**
 * @author Michael
 * @date  2018/12/12 - 11:22.
 */
class OverdueActivityViewModel(var overdueActivityRepository: BasePageRepository<OutlistParam>) : BaseViewModel() {

    var listdata = overdueActivityRepository.loadAndroidData()
    var networkState= Transformations.switchMap(listdata){
        overdueActivityRepository.networkState
    }!!

    /**
     * 点击item
     */
    fun onClickItem(view: View, item: OutlistParam) {
//        跟进：archive.purge 1
//        订车：archive.order 5
//        提车：archive.thenend 10
//        战败：archivecheck.fail 32
        var nkey = when (item.state) {
            "1" -> "archive.purge"
            "5" -> "archive.order"
            "10" -> "archive.thenend"
            "32" -> "archivecheck.fail"
            else -> ""
        }

        var intent = Intent(view.context, DefeatDetailsActivity::class.java)
        intent.putExtra("tid", item.tid)
        intent.putExtra("nkey", nkey)
        view.context.startActivity(intent)
    }

    /**
     * 刷新
     */
    fun refresh() {
        overdueActivityRepository.dataSourceFactory.sourceLiveData.value?.invalidate()
    }
}